package com.wande.dataplatform.filecollection.common.constant;

/**
 * 文件采集模块常量定义
 *
 * @author wande
 */
public class FileCollectionConstants {

    /**
     * 文件类型常量
     */
    public static class FileType {
        public static final String CSV = "CSV";
        public static final String XLS = "XLS";
        public static final String XLSX = "XLSX";
        public static final String XML = "XML";
        public static final String JSON = "JSON";
        public static final String SQL = "SQL";
        public static final String ACCDB = "ACCDB";
        public static final String PDF = "PDF";
        public static final String DOC = "DOC";
        public static final String DOCX = "DOCX";
        public static final String TXT = "TXT";
    }

    /**
     * 文件来源类型
     */
    public static class SourceType {
        public static final String LOCAL = "LOCAL";
        public static final String FTP = "FTP";
        public static final String SFTP = "SFTP";
        public static final String HTTP = "HTTP";
        public static final String OSS = "OSS";
    }

    /**
     * 调度类型
     */
    public static class ScheduleType {
        public static final String REALTIME = "REALTIME";
        public static final String HOURLY = "HOURLY";
        public static final String DAILY = "DAILY";
        public static final String WEEKLY = "WEEKLY";
        public static final String MONTHLY = "MONTHLY";
        public static final String MANUAL = "MANUAL";
    }
    
    // 向后兼容的常量
    public static final String SCHEDULE_TYPE_MANUAL = ScheduleType.MANUAL;

    /**
     * 入库策略
     */
    public static class LoadStrategy {
        public static final String OVERWRITE = "OVERWRITE";  // 全量覆盖
        public static final String APPEND = "APPEND";        // 增量追加
        public static final String UPSERT = "UPSERT";        // 按主键更新
    }
    
    // 向后兼容的常量
    public static final String LOAD_STRATEGY_OVERWRITE = LoadStrategy.OVERWRITE;
    public static final String LOAD_STRATEGY_UPSERT = LoadStrategy.UPSERT;

    /**
     * 采集规则状态
     */
    public static class RuleStatus {
        public static final String ENABLED = "ENABLED";
        public static final String DISABLED = "DISABLED";
    }
    
    // 向后兼容的常量
    public static final String RULE_STATUS_ENABLED = RuleStatus.ENABLED;

    /**
     * 任务状态
     */
    public static class TaskStatus {
        public static final String PENDING = "PENDING";
        public static final String RUNNING = "RUNNING";
        public static final String SUCCESS = "SUCCESS";
        public static final String FAILED = "FAILED";
        public static final String STOPPED = "STOPPED";
    }
    
    // 向后兼容的常量
    public static final String TASK_STATUS_PENDING = TaskStatus.PENDING;
    public static final String TASK_STATUS_RUNNING = TaskStatus.RUNNING;
    public static final String TASK_STATUS_SUCCESS = TaskStatus.SUCCESS;
    public static final String TASK_STATUS_FAILED = TaskStatus.FAILED;

    /**
     * 文件记录状态
     */
    public static class FileStatus {
        public static final String PENDING = "PENDING";
        public static final String PARSING = "PARSING";
        public static final String LOADING = "LOADING";
        public static final String SUCCESS = "SUCCESS";
        public static final String FAILED = "FAILED";
    }
    
    // 向后兼容的常量
    public static final String FILE_STATUS_PENDING = FileStatus.PENDING;
    public static final String FILE_STATUS_PARSING = FileStatus.PARSING;
    public static final String FILE_STATUS_SUCCESS = FileStatus.SUCCESS;
    public static final String FILE_STATUS_FAILED = FileStatus.FAILED;

    /**
     * 上传类型
     */
    public static class UploadType {
        public static final String MANUAL = "MANUAL";  // 手动上传
        public static final String AUTO = "AUTO";      // 自动采集
    }

    /**
     * 错误处理策略
     */
    public static class ErrorHandlingStrategy {
        public static final String SKIP_RECORD = "SKIP_RECORD";      // 跳过错误记录
        public static final String MARK_ERROR = "MARK_ERROR";        // 标记错误
        public static final String STOP_TASK = "STOP_TASK";          // 终止任务
    }

    /**
     * 错误类型
     */
    public static class ErrorType {
        public static final String FILE_NOT_FOUND = "FILE_NOT_FOUND";
        public static final String PARSE_ERROR = "PARSE_ERROR";
        public static final String VALIDATION_ERROR = "VALIDATION_ERROR";
        public static final String LOAD_ERROR = "LOAD_ERROR";
        public static final String NETWORK_ERROR = "NETWORK_ERROR";
        public static final String PERMISSION_ERROR = "PERMISSION_ERROR";
    }

    /**
     * 默认配置
     */
    public static class DefaultConfig {
        public static final int BATCH_SIZE = 1000;              // 批量大小
        public static final int THREAD_POOL_SIZE = 4;           // 线程池大小
        public static final long STREAM_THRESHOLD = 100 * 1024 * 1024L;  // 流式解析阈值 100MB
        public static final long MAX_FILE_SIZE = 500 * 1024 * 1024L;     // 最大文件大小 500MB
        public static final int RETRY_TIMES = 3;                // 重试次数
        public static final int TIMEOUT_SECONDS = 300;          // 超时时间 5分钟
    }

    /**
     * MinIO配置
     */
    public static class MinioConfig {
        public static final String BUCKET_NAME = "file-collection";
        public static final String STRUCTURED_PREFIX = "structured/";
        public static final String UNSTRUCTURED_PREFIX = "unstructured/";
    }

    /**
     * MinIO存储桶常量
     */
    public static final String MINIO_BUCKET_UNSTRUCTURED = "unstructured-files";

    /**
     * 字段类型
     */
    public static class FieldType {
        public static final String STRING = "STRING";
        public static final String INTEGER = "INTEGER";
        public static final String LONG = "LONG";
        public static final String DOUBLE = "DOUBLE";
        public static final String DECIMAL = "DECIMAL";
        public static final String BOOLEAN = "BOOLEAN";
        public static final String DATE = "DATE";
        public static final String DATETIME = "DATETIME";
        public static final String TIMESTAMP = "TIMESTAMP";
    }

    /**
     * 转换函数
     */
    public static class TransformFunction {
        public static final String UPPER = "UPPER";              // 转大写
        public static final String LOWER = "LOWER";              // 转小写
        public static final String TRIM = "TRIM";                // 去空格
        public static final String SUBSTRING = "SUBSTRING";      // 字符串截取
        public static final String REPLACE = "REPLACE";          // 字符串替换
        public static final String REGEX_REPLACE = "REGEX_REPLACE";  // 正则替换
        public static final String DATE_FORMAT = "DATE_FORMAT";  // 日期格式化
        public static final String CONCAT = "CONCAT";            // 字符串拼接
    }

    /**
     * 校验规则类型
     */
    public static class ValidationRuleType {
        public static final String NOT_NULL = "NOT_NULL";        // 非空校验
        public static final String FORMAT = "FORMAT";            // 格式校验
        public static final String RANGE = "RANGE";              // 范围校验
        public static final String ENUM = "ENUM";                // 枚举值校验
        public static final String UNIQUE = "UNIQUE";            // 唯一性校验
        public static final String CUSTOM = "CUSTOM";            // 自定义校验
    }
}
